﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Promotion_Promotion4List : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        //查询条件
        DateTime result = DateTime.Now;
        DateTime sDate = DateTime.TryParse(Text1.Value, out result) ? result : DateTime.MinValue;
        DateTime eDate = DateTime.TryParse(Text2.Value, out result) ? result : DateTime.MaxValue;
        int value = 0;
        int status = int.TryParse(ddl_State.SelectedValue, out value) ? value : 0;
        DataSet ds = new BLL.CXFAD8().GetListByCondition("CXFAD8", txtDJBH.Text.Trim(), sDate, eDate, status);
        grdCXFAD8.DataSource = ds.Tables[0];
        grdCXFAD8.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Promotion4Edit.aspx");
    }
    protected void Btn_Search_Click(object sender, EventArgs e)
    {
        Bind();
    }
    protected void grdCXFAD8_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if ((e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Alternate))
        {
            int value = 0;
            int status = int.TryParse(((Label)e.Row.Cells[3].FindControl("Label11")).Text, out value) ? value : 0;
            switch (status)
            {
                case 1:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "有效";
                    break;
                case 2:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "未审核";
                    break;
                case 3:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "已审核";
                    break;
                case 4:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "运行中";
                    break;
                case 5:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "已停止";
                    break;
                case 6:
                    ((Label)e.Row.Cells[3].FindControl("Label11")).Text = "无效";
                    break;
                default:
                    break;
            }
                string DJBH = ((HtmlInputHidden)e.Row.FindControl("Hid_ID")).Value;

                LinkButton valid = (LinkButton)e.Row.FindControl("Lbtn_Valid");
                LinkButton stop = (LinkButton)e.Row.FindControl("Lbtn_Stop");
                LinkButton Run = (LinkButton)e.Row.FindControl("Lbtn_Run");
                LinkButton NoRun = (LinkButton)e.Row.FindControl("Lbtn_NoRun");
                HtmlInputHidden Jz = (HtmlInputHidden)e.Row.FindControl("Hid_Auidt");
                HtmlInputHidden Sp = (HtmlInputHidden)e.Row.FindControl("Hid_Sp");
                HtmlInputHidden run = (HtmlInputHidden)e.Row.FindControl("Hid_Run");
                if (Sp.Value == "0" && Jz.Value == "0")
                {
                    valid.Visible = true;
                    stop.Visible = true;
                    Run.Visible = false;
                    NoRun.Visible = false;
                }
                if (Sp.Value == "1")
                {
                    valid.Visible = false;
                    stop.Visible = false;
                    Run.Visible = false;
                    NoRun.Visible = false;
                }
                if (Sp.Value == "0" && Jz.Value == "1" && run.Value == "0")
                {
                    valid.Visible = false;
                    stop.Visible = true;
                    Run.Visible = true;
                    NoRun.Visible = false;
                }
                if (Sp.Value == "0" && Jz.Value == "1" && run.Value == "1")
                {
                    valid.Visible = false;
                    stop.Visible = false;
                    Run.Visible = false;
                    NoRun.Visible = true;
                }
            }
    }
    protected void grdCXFAD8_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grdCXFAD8.EditIndex = -1;
        Bind();
    }
    protected void grdCXFAD8_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string djbh = e.CommandArgument.ToString();
        int checkInt;
        try
        {
            switch (e.CommandName)
            {
                case "Valid":
                    checkInt = new BLL.CXFAD8().UpdateCXFADStatus(djbh, "JZ");
                    break;
                case "Stop":
                    checkInt = new BLL.CXFAD8().UpdateCXFADStatus(djbh, "SP");
                    break;
                case "Run":
                    checkInt = new BLL.CXFAD8().UpdateCXFADStatus(djbh, "RUN");
                    break;
                case "NoRun":
                    checkInt = new BLL.CXFAD8().UpdateCXFADStatus(djbh, "NORUN");
                    break;
                default:
                    break;
            }


           Bind();

        }
        catch (Exception ee)
        {
            Share.Alert(this, "操作失败");
            return;
        }
    }
    protected void grdCXFAD8_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdCXFAD8.PageIndex = e.NewPageIndex;
        Bind();

    }
    protected void grdCXFAD8_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grdCXFAD8.EditIndex = e.NewEditIndex;
        Bind();
    }
}
